/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_DB_MYSQL_MYSQLSQLCONNECTION_H_
#define SHARED_DB_MYSQL_MYSQLSQLCONNECTION_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <mysql.h>
#include "Shared/DB/SqlConnection.h"


namespace Shared {
namespace DB {
namespace MySQL {

    class MySQLSqlConnection: public SqlConnection
    {
    public:
        MySQLSqlConnection(Database& db);
        virtual ~MySQLSqlConnection(void);

    public:
        virtual bool open(const std::string &host,
            const std::string &port, const std::string &user,
            const std::string &pass, const std::string &db, 
            bool autoReconnect = true);
        virtual void close(void);

        virtual QueryResult *query(const std::string &sql);
        virtual bool execute(const std::string &sql);
        virtual void ping(void);
        virtual bool beginTransaction(void);
        virtual bool commitTransaction(void);
        virtual bool rollbackTransaction(void);

    private:
        bool transactionCmd(const char *cmd);

        MYSQL*  _my;            
    };

}}}

#endif // SHARED_DB_MYSQL_MYSQLSQLCONNECTION_H_
